/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoopp.framework;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import java.io.DataOutputStream;
import java.io.File;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;

public final class i {
    public final boolean a(String paramString, Map paramMap, d[] paramArrayOfd)
  {
    int i = 0;
    String str1 = UUID.randomUUID().toString();
    String str2 = "--";
    String str3 = "\r\n";
    String str4 = "multipart/form-data";
    String str5 = "UTF-8";
    (paramString = (HttpURLConnection)new URL(paramString).openConnection()).setReadTimeout(5000);
    paramString.setDoInput(true);
    paramString.setDoOutput(true);
    paramString.setUseCaches(false);
    paramString.setRequestMethod("POST");
    paramString.setRequestProperty("connection", "keep-alive");
    paramString.setRequestProperty("Charsert", "UTF-8");
    paramString.setRequestProperty("Content-Type", str4 + ";boundary=" + str1);
    int j = 0;
    Iterator localIterator;
    if (paramArrayOfd != null)
    {
      int i1 = (localObject1 = paramArrayOfd).length;
      for (int i2 = 0; i2 < i1; ++i2)
        if ((localIterator = localObject1[i2]).a != null)
        {
          LogUtil.w("HttpSend", "post, getInStream != null.");
          j = (int)(j + localIterator.b.length());
        }
        else
        {
          LogUtil.w("HttpSend", "post, getInStream == null.");
          j += localIterator.a().length;
        }
    }
    Object localObject1 = null;
    Object localObject3;
    if (paramMap != null)
    {
      (localObject2 = new HashMap()).put("token", paramMap.get("token="));
      localObject3 = System.currentTimeMillis();
      ((HashMap)localObject2).put("ts", localObject3);
      ((HashMap)localObject2).put("sign", a((HashMap)localObject2, ((String)paramMap.get("seckey=")) + j));
      localObject1 = new StringBuilder();
      localIterator = ((HashMap)localObject2).entrySet().iterator();
      while (localIterator.hasNext())
      {
        Map.Entry localEntry = (Map.Entry)localIterator.next();
        ((StringBuilder)localObject1).append(str2);
        ((StringBuilder)localObject1).append(str1);
        ((StringBuilder)localObject1).append(str3);
        ((StringBuilder)localObject1).append("Content-Disposition: form-data; name=\"" + ((String)localEntry.getKey()) + "\"" + str3);
        ((StringBuilder)localObject1).append("Content-Type: text/plain; charset=" + str5 + str3);
        ((StringBuilder)localObject1).append("Content-Transfer-Encoding: 8bit" + str3);
        ((StringBuilder)localObject1).append(str3);
        ((StringBuilder)localObject1).append((String)localEntry.getValue());
        ((StringBuilder)localObject1).append(str3);
      }
    }
    Object localObject2 = new DataOutputStream(paramString.getOutputStream());
    if (paramMap != null)
      ((DataOutputStream)localObject2).write(((StringBuilder)localObject1).toString().getBytes());
    if (paramArrayOfd != null)
    {
      for (paramMap : paramArrayOfd)
      {
        (paramArrayOfd = new StringBuilder()).append(str2);
        paramArrayOfd.append(str1);
        paramArrayOfd.append(str3);
        paramArrayOfd.append("Content-Disposition: form-data; name=\"" + paramMap.c + "\"; filename=\"" + paramMap.c + "\"" + str3);
        paramArrayOfd.append("Content-Type: application/octet-stream; charset=" + str5 + str3);
        paramArrayOfd.append(str3);
        ((DataOutputStream)localObject2).write(paramArrayOfd.toString().getBytes());
        LogUtil.w("HttpSend", "uploadFile, file name is : " + paramMap.c);
        if (paramMap.a != null)
        {
          paramArrayOfd = new byte[1024];
          int l = 0;
          while ((l = paramMap.a.read(paramArrayOfd, 0, 1024)) != -1)
            ((DataOutputStream)localObject2).write(paramArrayOfd, 0, l);
          paramMap.a.close();
        }
        else
        {
          ((DataOutputStream)localObject2).write(paramMap.a(), 0, paramMap.a().length);
        }
        ((DataOutputStream)localObject2).write(str3.getBytes());
      }
      localObject3 = str2 + str1 + str2 + str3.getBytes();
      ((DataOutputStream)localObject2).write(localObject3);
      ((DataOutputStream)localObject2).flush();
      InputStream localInputStream = null;
      if (( = paramString.getResponseCode()) == 200)
      {
        localInputStream = paramString.getInputStream();
        paramArrayOfd = new StringBuilder();
        while ((paramMap = localInputStream.read()) != -1)
          paramArrayOfd.append((char)paramMap);
        LogUtil.w("HttpSend", "post, result is : " + paramArrayOfd.toString());
        if (paramArrayOfd.toString().contains("succ"))
          i = 1;
      }
      else
      {
        LogUtil.w("HttpSend", "post, failed, code is : " + ???);
      }
      ((DataOutputStream)localObject2).close();
      paramString.disconnect();
    }
    return i;
  }

    public static boolean a(Context paramContext) {
        if ((paramContext = ((ConnectivityManager) paramContext.getSystemService("connectivity")).getAllNetworkInfo()) != null)
            for (int i = 0; i < paramContext.length; ++i)
                if (paramContext[i].getState() == NetworkInfo.State.CONNECTED)
                    return true;
        return false;
    }

    private String a(HashMap paramHashMap, String paramString) {
        Collections.sort(paramHashMap = new ArrayList(paramHashMap.entrySet()), new j(this));
        StringBuilder localStringBuilder = new StringBuilder();
        paramHashMap = paramHashMap.iterator();
        while (paramHashMap.hasNext()) {
            Map.Entry localEntry = (Map.Entry) paramHashMap.next();
            localStringBuilder.append((String) localEntry.getKey()).append("=").append((String) localEntry.getValue())
                    .append("&");
        }
        if (localStringBuilder.toString().endsWith("&"))
            localStringBuilder.deleteCharAt(localStringBuilder.length() - 1);
        localStringBuilder.append(paramString);
        paramHashMap = MD5.getMD5(localStringBuilder.toString());
        LogUtil.d("HttpSend", "MD5Sign=" + paramHashMap);
        return paramHashMap;
    }
}